home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_06_07 / v6n7074a.txt < prev    next >
Text File  |  1989-09-26  |  2KB  |  71 lines

  1. /* argument() function for device driver
  2.  
  3. SYNOPSIS
  4.  
  5.      #include "dd.h"
  6.  
  7.      s = argument(n);
  8.  
  9.      int n;             number of argument desired
  10.      char *s;           n-th argument
  11.  
  12. DESCRIPTION
  13.  
  14. This function, when called from the init() function, returns the text of the
  15. n-th argument in the line in the CONFIG.SYS file used to install the driver.
  16. The 0-th argument is the file specification for the driver.  If there is no
  17. n-th argument, the function returns NULL.  If the argument is more than 64
  18. characters long, it is truncated to that length.  For example, if the driver
  19. is installed by the following line
  20.  
  21.      DEVICE=RAMDISK.SYS 200 64
  22.  
  23. then
  24.  
  25.      argument(0)  is  "RAMDISK.SYS"
  26.      argument(1)  is  "200"
  27.      argument(2)  is  "64"
  28.      argument(3)  is  NULL
  29.  
  30. CAUTION
  31.  
  32. The function uses a single internal buffer, so the returned string is
  33. destroyed by the next call.  If it is called from outside the init()
  34. function, it will return nonsense.  It uses the pointer 
  35.  
  36.      request_header->x.init.pointer.command_line
  37.  
  38. which overlays the pointer
  39.  
  40.      request_header->x.init.pointer.bpb_table
  41.  
  42. Therefore, it cannot be successfully called after the latter pointer has been
  43. initialized by a block device driver.
  44.  
  45. */
  46.  
  47. #include "dd.h"
  48.  
  49. #define MAXIMUM_ARGUMENT_LENGTH 64
  50.  
  51. char *argument(n) int n; {
  52. static char buffer[MAXIMUM_ARGUMENT_LENGTH+1];
  53. char *p;
  54. int c;
  55. p = request_header->x.init.pointer.command_line;
  56. c = *p++;
  57. while (n>=0) {
  58.   int i;
  59.   while (c==' ' || c=='\t' || c==0) c = *p++;
  60.   if (c=='\r' || c=='\n') return NULL;
  61.   i = 0;
  62.   while (c!=' ' && c!='\t' && c!=0 && c!='\r' && c!='\n') {
  63.     if (i<MAXIMUM_ARGUMENT_LENGTH) buffer[i++] = c;
  64.     c = *p++;
  65.     }
  66.   buffer[i] = 0;
  67.   n--;
  68.   }
  69. return buffer;
  70. }
  71.